#!/bin/bash
# PostgreSQL Database Viewer - Linux/macOS Launcher
# This script launches the database viewer on Linux/macOS

echo "Starting PostgreSQL Database Viewer..."
echo

# Check if Python is installed
if ! command -v python3 &> /dev/null; then
    echo "Error: Python 3 is not installed or not in PATH"
    echo "Please install Python 3.7 or higher"
    exit 1
fi

# Check if required files exist
if [ ! -f "tkinter_viewer.py" ]; then
    echo "Error: tkinter_viewer.py not found"
    echo "Please ensure you are in the correct directory"
    exit 1
fi

# Install dependencies if needed
echo "Checking dependencies..."
pip3 install -r requirements.txt > /dev/null 2>&1

# Launch the application
echo "Launching Database Viewer..."
python3 tkinter_viewer.py

# Check exit status
if [ $? -ne 0 ]; then
    echo
    echo "An error occurred. Please check the error messages above."
    read -p "Press Enter to exit..."
fi
